<!--{include admin/top.html}-->
	<style>
		.nrow{
			line-height:40px;
		}
		.nrow td{
			line-height:30px;
			padding:4px;
		}
	</style>
	<div class="mainPage">
		<!--{if $act == 'index'}-->
			<h1 class="title">模板中心
			<span class="sub_menu"><a href="{:parse_uri('admin_tpl-mgr|true')}">本地模板</a></span>
			</h1>
			<div>
			<!--{foreach $tpls $k $v}-->
			{if ($k+1) % 4 === 0}
				<div style="clear:both"></div>
			{/if}
			<div class="tpl-div" style="position:relative;{if in_array($v['theme_code'],$tplKeys)}background:#aaa{/if}">
				<img src="{$v['theme_pic']}"/>
				<p style="margin-top:4px;"><b>{$v['theme_name']}</b> 
					{if in_array($v['theme_code'],$tplKeys)}
						{if $v['theme_code'] != $curTpl}
								<a href="{:parse_uri("admin_tpl-enable-k-%s",base64_encode($v['theme_code']))}"><span style="font-size:12px;color:#007;font-weight:bolder">设为默认</span></a>
						{else}
								<span style="font-size:12px;color:#700;font-weight:bolder">当前默认</span>
						{/if}
					{/if}
				</p>
				<p>
					<span>作者: </span> <a href="{$v['theme_homepage']}" style="color:#509" target="_blank">{$v['theme_author']}</a>
					&nbsp;&nbsp;<span>价格: </span> <b style="color:red">{$v['theme_auth']}</b> 元
				</p>
				<p><span>颜色: </span>{$v['theme_color']}
				&nbsp;&nbsp;<span>适用: </span> <b style="color:blue">V {$v['ver']}</b>
				</p>
				<p><span>日期: </span> {:date('Y-m-d H:i',$v['theme_date'])}
				{if !in_array($v['theme_code'],$tplKeys)}
				&nbsp;&nbsp;[&nbsp;<a href="{_ORA_UPDATE_}?t={$v['theme_code']}" target="_blank">预览</a>&nbsp;]
				&nbsp;[&nbsp;<a href="{:parse_uri('admin_tpl-install-key-%s',base64_encode($v['theme_code']))}">安装</a>&nbsp;]
				{/if}
				</p>
				{if $v['theme_code'] == $curTpl}
				<div style="position:absolute;top:180px;right:1px;background:url({__PUBLIC__}/images/inuse.png) no-repeat right bottom;width:152px;height:143px;" > </div>
				{/if}
			</div>
			<!--{/foreach}-->
			
			<div style="clear:both"></div>
			</div>
		<!--{elseif $act == 'add'}-->
			<h1 class="title">添加模板
			<span class="sub_menu"><a href="{:parse_uri('admin_tpl-index|true')}">返回列表</a></span>
			</h1>
			<p>
			<form style="margin:0;padding:0;" method="post" action="{:parse_uri('admin_tpl-upload|true')}" enctype="multipart/form-data">
			本地上传: <input type="file" name="userfile[]" class="ipt" style="height:21px;" />
			<input type="submit" name="submit" style="height:21px;" value="上传" />
			</form>
			</p>
			<ol>
				<li style="line-height:24px;color:gray;font-size:13px;">
					文件规范: <span class="errmsg" style="font-size:13px;"> 请参考默认主题 </span> 
				</li>
				<li style="line-height:24px;color:gray;font-size:13px;">
					文件格式: <span class="errmsg" style="font-size:13px;">zip </span>
				</li>
				<li style="line-height:24px;color:gray;font-size:13px;">
					文件大小: <span class="errmsg" style="font-size:13px;"> 2 </span> M 
				</li>
			</ol>
				
		<!--{elseif $act == 'install'}-->

			<script>
				var post = false;
				var end = false;
				var cnum = 0;
				function start(obj){
					if(post == false){
						$(obj).text("安装中...");
						getProcess();
						$.get("{:parse_uri('admin_tpl-doInstall-key-%s',base64_encode($key))}",function(d){
							if(d == 'fail'){
								alert('安装失败,模板包错误!');	
							}
						});
						post = true;
					}else{
						if(end){
							alert("您已经安装过了!");
							return false;
						}else{
							alert("安装中,请稍候!");
							return false;
						}
					}
				}

				function getProcess(){
					var timenow = new Date().getTime();
					$.get("{_HTTP_HOST_}/upload/now?"+timenow,function(data){
						cnum = parseInt(data);
						$("#process").css("color","#999");
						$("#process").css("background","#333");
						$("#process").css("width",(data+"%"));
						$("#process").html(data + "%");
						$("#slink").text("已完成 "+ data + "% ,请稍候...");
						
					});
					if( cnum == 100 ){
							$.get("{:parse_uri('admin_tpl-delNow')}");
							end = true;
							$("#slink").text("安装完成!");
							if(confirm("安装完成! 是否立即启用该模板?")){
								$.get("{:parse_uri('admin_tpl-enable-k-%s-isAjax-1',base64_encode($key))}",function(data){
									if(data=="true"){
										alert("启用完成!");
										location.href = '{:parse_uri('admin_tpl-index')}';
									}else{
										alert("启用失败!");
									}
								});
							}
							return false;
					}else{
						setTimeout("getProcess()",500);
					}
				}

			</script>
			<h1 class="title">安装模板 <span style="color:Red">{$tpls[$key]['theme_name']}</span> &nbsp;&nbsp;
			<span class="sub_menu"><a href="{:parse_uri('admin_tpl-index|true')}">返回列表</a></span>
			</h1>
			<ul style="list-style:none">
				<li style="line-height:24px;color:#333;font-size:13px;">
					适用版本: ORA v <span class="errmsg" style="font-size:13px;"> {$tpls[$key]['ver']} </span> 
				</li>
				<li style="line-height:24px;color:#333;font-size:13px;">
					文件大小: <span class="errmsg" style="font-size:13px;"> {:round($fileSize/1024/1024,3)} </span> M 
				</li>
				<li style="padding-top:10px;">
					<div style="width:300px;color:#666;height:20px;background:#fff;border:1px solid #333;">
						<div id="process" style="background:#333;height:18px;color:#fff;border:1px solid #555;text-indent:10px;">准备安装...</div>
					</div>
				</li>
				<li style="padding-top:10px;">
					<a href="javascript:void(0)" Id="slink" onclick="start(this)" style="font-size:13px;color:Red;font-weight:bolder" >点击安装!</a>
				</li>
			</ul>
			
		<!--{elseif $act == 'mgr'}-->
			<h1 class="title">本地模板
			<span class="sub_menu"><a href="{:parse_uri('admin_tpl-add|true')}">添加模板</a></span>
			<span class="sub_menu"><a href="{:parse_uri('admin_tpl-index|true')}">返回列表</a></span>
			</h1>
			<div>
			<!--{foreach $tpls $k $v}-->
			{if ($k+1) % 4 === 0}
				<div style="clear:both"></div>
			{/if}
			<div class="tpl-div" style="position:relative;{if in_array($v['theme_code'],$tplKeys)}background:#aaa{/if}">
				<img src="{_HTTP_HOST_}/themes/{$v['theme_pic']}"/>
				<p style="margin-top:4px;"><b>{$v['theme_name']}</b> </p>
				<p>
					<span>作者: </span> <a href="{$v['theme_homepage']}" style="color:#509" target="_blank">{$v['theme_author']}</a>
					&nbsp;&nbsp;<span>价格: </span> <b style="color:red">{$v['theme_auth']}</b> 元
				</p>
				<p><span>颜色: </span>{$v['theme_color']}
				&nbsp;&nbsp;<span>适用: </span> <b style="color:blue">V {$v['ver']}</b>
				</p>
				<p><span>日期: </span> {:date('Y-m-d H:i',$v['theme_date'])} {if $v['theme_code'] != $curTpl}<a href="{:parse_uri('admin_tpl-del-id-%d',$v['Id'])}">删除该模板</a>{/if}
				</p>
				{if $v['theme_code'] == $curTpl}
				<div style="position:absolute;top:180px;right:1px;background:url({__PUBLIC__}/images/inuse.png) no-repeat right bottom;width:152px;height:143px;" > </div>
				{/if}
			</div>
			<!--{/foreach}-->
			
			<div style="clear:both"></div>
			</div>
		<!--{/if}-->
	</div>
</body>
</html>